package common;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Optional;
import org.testng.annotations.Parameters;

/**
 * This class will be extended from all test cases
 * Will handle the setup and tear down of each test
 * Starting and stopping the driver
 */

public class WebDriverInit {
	protected WebDriver driver;
    private static final Log log = LogFactory.getLog(WebDriverInit.class);
    
	@BeforeClass(alwaysRun = true)
    @Parameters({"selenium.url"})
    public void startDriver(@Optional(value="http://advancedpersonality.visualdna.com/") String url){
	log.info("Starting the Browser at " + url);
	this.driver = new FirefoxDriver();
	this.driver.get(url);
	log.info("Browser Started");
    }
	
	@AfterClass(alwaysRun = true)
    public void stopSelenium() {
		try {
			Thread.sleep(10000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		log.info("Close the browser");
    	this.driver.close();
    	this.driver.quit();
    	log.info("Browser Closed");
    }
	
}
